<template>
	<view class="container">
		<view class="header">
			<view class="tab_box">
				<view class="tab" :class="current == 0?'active':''" @click="tabClick(0)">储值卡</view>
				<view class="tab" :class="current == 1?'active':''" @click="tabClick(1)">礼品卡</view>
			</view>
			<view class="vip_card" v-if="current == 0">
				<image src="@/static/images/default_headimg.png" mode=""></image>
				<view class="money">
					<view>
						<view class="small">储值卡可用余额</view>
						<view class="price"><text>￥</text>23333.00</view>
					</view>
				</view>
				<view style="display: flex;align-items: flex-start;height: 130rpx;">
					<view class="recharge" @click="$gourl('/pages/index/recharge')">绑卡充值</view>
				</view>
			</view>
			<view class="gift_card" v-if="current == 1">
				<view class="title">激活定制礼卡</view>
				<view class="option_box">
					<view class="label">礼卡类型：</view>
					<view class="value">
						<u-radio-group v-model="value" @change="radioGroupChange" size="28">
							<u-radio @change="radioChange" v-for="(item, index) in list" active-color="red" :key="index"
								:name="item.name">
								{{item.name}}
							</u-radio>
						</u-radio-group>
					</view>
				</view>
				<view v-if="value == '礼卡卡号密码'">
					<view class="option_box">
						<view class="label">礼卡卡号：</view>
						<view class="value">
							<input type="text" v-model="tihuoCardkm.number" placeholder="请输入礼卡卡号">
						</view>
					</view>
					<view class="option_box">
						<view class="label">礼卡密码：</view>
						<view class="value">
							<input type="text" v-model="tihuoCardkm.password" placeholder="请输入礼卡密码">
						</view>
					</view>
				</view>
				<view v-if="value == '礼卡手机号验证码'">
					<view class="option_box">
						<view class="label">手机号：</view>
						<view class="value">
							<input type="text" placeholder="请输入手机号" v-model="phone">
						</view>
					</view>
					<view class="option_box">
						<view class="label">验证码：</view>
						<view class="value">
							<input type="text" placeholder="请输入验证码">
							<view class="yz_btn" @click="sendCode" v-if="sendYes">发送验证码</view>
							<view class="yz_btn" v-else>发送{{times}}S</view>
						</view>
					</view>
				</view>
				<view class="jh_btn" @click="giftCard">激活定制礼卡</view>
				<view class="tips">提示：实体卡请用卡号密码激活，虚拟卡请用手机号和验证码激活</view>
			</view>
		</view>
		<view class="line"></view>
		<view class="detailed_box" v-if="current ==1">
			<view class="title">礼品卡明细</view>
			<view class="mx_box">
				<view class="list" v-for="(item,index) in tihuoList" :key="index">
					<view class="left">
						<view class="big">{{item.name}}<text>{{statusFun(item.status)}}</text></view>
						<view class="time">{{$dTime(item.bind_time)}}</view>
					</view>
					<view class="right">
						<view class="big">{{item.status ==2?'已提货':'未提货'}}</view>
						<view class="small_btn"
							@click="$gourl('/pages/index/cardDetails?id='+item.gift_card_id+'&data='+JSON.stringify(item))">
							查看提货商品
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="detailed_box" v-if="current == 0">
			<view class="title">储值卡明细</view>
			<view class="mx_box">
				<view class="list">
					<view class="left">
						<view class="big">绑卡充值</view>
						<view class="time">2022-12-12 22:22:22</view>
					</view>
					<view class="right">+200
					</view>
				</view>
			</view>
		</view>
		<view class="buttons" v-if="current == 0">绑定充值</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 1,
				value: '礼卡卡号密码',
				times: 59,
				sendYes: true,
				phone: '',
				list: [{
						name: '礼卡卡号密码',
						disabled: false
					},
					{
						name: '礼卡手机号验证码',
						disabled: false
					}
				],
				tihuoCardkm: {
					type: 1,
					number: '',
					password: ''
				},
				tihuoList: [],
				listQuery: {
					page: 1,
					pageSize: 20,
					gift_type: 1,
				},
				total: 1
			}
		},
		onLoad() {
			this.getHistroyList()

		},
		methods: {
			tabClick(index) {
				this.current = index
				this.getHistroyList()
			},
			radioGroupChange(e) {
				console.log(e);
			},
			radioChange(e) {
				console.log(e);
			},
			statusFun(status) {
				switch (status) {
					case '0':
						return '未激活'
						break;
					case '1':
						return '已激活未使用'
						break
					default:
						return '已提货'
				}
			},
			giftCard() {
				let info = null
				if (this.value == '礼卡卡号密码') {
					info = this.tihuoCardkm
				}
				this.$allApi.bindGiftCard(info).then(res => {
					console.log(res);
					this.$u.toast('激活绑定成功')
					this.getHistroyList()
				})
			},
			getHistroyList() {
				if (this.current == 0) {
					this.listQuery.gift_type = 2
				} else {
					this.listQuery.gift_type = 1
				}
				this.$allApi.getGiftCardHistory(this.listQuery).then(res => {
					console.log(res);
					this.tihuoList = res.data.list
				})
			},
			sendCode() {
				if (this.phone == '') {
					this.$u.toast('手机号码不能为空')
					return
				}
				this.$allApi.sendCode({
					mobile: this.phone,
					type: 'login',
					token: this.imageCodeData.imageToken,
					yzm: this.imgCodeContent
				}).then(res => {
					console.log(res);
					this.sendYes = false
					let timer = setInterval(() => {
						console.log(this.times--);
					}, 1000)
					setTimeout(() => {
						clearInterval(timer)
						this.sendYes = true
						this.times = 59
					}, 50000)
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.gift_card {
		padding: 30rpx;

		.title {
			font-size: 32rpx;
			margin-bottom: 20rpx;
		}

		.jh_btn {
			width: 536rpx;
			height: 78rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			background: #ff3b3b;
			margin: 30rpx auto;
			border-radius: 10rpx;
		}

		.tips {
			font-size: 24rpx;
		}

		.option_box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 20rpx;

			.label {
				width: 140rpx;
				color: #888;
			}

			.value {
				display: flex;
				align-items: center;
				flex: 1;
				font-size: 24rpx;

				.yz_btn {
					width: 164rpx;
					height: 62rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #ff3b3b;
					border: #ff3b3b 1px solid;
					border-radius: 10rpx;
					margin-left: 20rpx;
				}

				input {
					flex: 1;
					font-size: 28rpx;
					height: 62rpx;
					border: 1px solid #eee;
					border-radius: 10rpx;
					padding: 0 20rpx;
				}
			}

		}
	}

	.mx_box {
		.list {
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-top: 1px solid #eee;
			padding: 30rpx 0;

			.left {
				padding-right: 30rpx;
				flex: 1;

				.big {
					text {
						color: #ff3b3b;
						margin-left: 20rpx;
					}
				}

				.time {
					font-size: 24rpx;
					color: #666;
				}
			}

			.right {
				font-size: 32rpx;
				font-weight: bold;
				text-align: right;
				color: #ff3b3b;

				.big {
					color: #333 !important;
				}

				.small_btn {
					font-size: 24rpx;
					color: #36b1ff;
					padding: 6rpx 16rpx;
					border: 1px solid #5d94ff;
					border-radius: 10rpx;
					margin-top: 20rpx;
				}
			}
		}
	}

	.detailed_box {
		padding: 0 30rpx;

		.title {
			font-size: 32rpx;
			padding: 30rpx 0;
		}
	}

	.line {
		height: 20rpx;
		background: #f8f8f8;
	}

	.header {
		position: sticky;
		top: 44px;
		left: 0;
		background: #fff;

		.recharge {
			padding: 10rpx 20rpx;
			border: 1px solid #ff3b3b;
			border-radius: 10rpx;
			color: #ff3b3b;
		}

		.vip_card {
			padding: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.money {
				padding: 0 20rpx;
				flex: 1;
				display: flex;
				align-items: center;

				.price {
					font-size: 32rpx;
					font-weight: bold;
					color: #ff3b3b;

					text {
						font-size: 12px;
					}
				}
			}

			image {
				width: 250rpx;
				height: 130rpx;
				border-radius: 20rpx;
			}
		}

		.tab_box {
			display: flex;
			align-items: center;
			justify-content: center;
			border-bottom: 1px solid #eee;

			.tab {
				font-size: 32rpx;
				padding: 20rpx 70rpx;
				color: #999;
				font-weight: bold;
			}

			.active {
				color: #ff3b3b;
				position: relative;
			}

			.active::after {
				content: '';
				border-bottom: 2px solid #ff3b3b;
				position: absolute;
				bottom: 0;
				left: 70rpx;
				width: 90rpx;
			}
		}
	}

	.container {
		// #ifdef H5
		min-height: calc(100vh - 44px);
		// #endif
		// #ifndef H5
		min-height: 100vh;
		// #endif
		position: relative;
		padding-bottom: 100rpx;
	}

	.buttons {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100vw;
		height: 100rpx;
		background: #ff3b3b;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
	}
</style>